package com.migo.api;

import com.migo.annotation.IgnoreAuth;
import com.migo.entity.MgAudioInfoEntity;
import com.migo.entity.MgAudioTypeEntity;
import com.migo.service.MgAudioInfoService;
import com.migo.service.MgAudioTypeService;
import com.migo.utils.PageUtils;
import com.migo.utils.Query;
import com.migo.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * pvmg10音乐素材管理
 * 
 * @author powervision
 * @email zhenrong.xu@powervision.me
 * @date 2021-04-08 18:58:36
 */
@CrossOrigin
@RestController
@RequestMapping("/api/mgAudioInfo")
public class ApiMgAudioInfoController {
	@Autowired
	private MgAudioInfoService mgAudioInfoService;

	@Autowired
	private MgAudioTypeService mgAudioTypeService;
	/**
	 * 列表
	 */
	@IgnoreAuth
	@RequestMapping("/audioInfoList")
	public R mgaudioinfolist(@RequestParam Map<String, Object> params){
		if(!params.containsKey("prodType")){
			params.put("prodType","pvmg10");
		}
		if(!params.containsKey("sidx")){
			params.put("sidx","id");
		}
		if(!params.containsKey("order")){
			params.put("order","asc");
		}
		if(!params.containsKey("audioType")){
			params.put("audioType",params.get("audioType"));
		}
		if (!params.containsKey("language")){
			params.put("language",params.get("language"));
		}
		int total = 0;
		//查询列表数据
		Query query = new Query(params);
		if (String.valueOf(params.get("language")).equals("en")){
			total = mgAudioInfoService.queryTotalList(query);
		}else {
			total = mgAudioInfoService.queryTotalListcn(query);
		}

		List<MgAudioInfoEntity> mgAudioInfoList = mgAudioInfoService.queryAudioInfoList(query);

		PageUtils pageUtil = new PageUtils(mgAudioInfoList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("data", pageUtil);
	}


	/**
	 * 查询音乐的分类和计数 列表
	 */
	@IgnoreAuth
	@RequestMapping("/audioTypeList")
	public R audioTypeList(@RequestParam Map<String, Object> params){
		if(!params.containsKey("prodType")){
			params.put("prodType","pvmg10");
		}

		if(!params.containsKey("order")){
			params.put("order","asc");
		}
		String language="zh";
		if(params.containsKey("language")){
			language= (String) params.get("language");
			if("".equals(language)){
				params.put("language","en");
			}
		}else{
			params.put("language","en");
		}
		//查询列表数据
		Query query = new Query(params);

		List<MgAudioTypeEntity> mgAudioTypeList = mgAudioTypeService.queryAudioTypeList(query);
		int total = mgAudioTypeService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(mgAudioTypeList, total, query.getLimit(), query.getPage());


		return R.ok().put("data", pageUtil);
	}


	/**
	 * 查询音乐的分类
	 */
	@IgnoreAuth
	@RequestMapping("/queryaudioType")
	public R audioTypeList(String language){
		List<MgAudioTypeEntity> mgAudioTypeEntities = mgAudioTypeService.queryaudioType(language);
		return R.ok().put("data", mgAudioTypeEntities);
	}

}
